package jjn.carl_round2;

import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-09-17 23:34
 */
public class LeetCode35 {
    
    public int searchInsert(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left <= right) {
            int mid = left + (right - left >> 1);
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), target = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        int searchedInsert = new LeetCode35().searchInsert(nums, target);
        System.out.println(searchedInsert);
    }
}
